import axios from 'axios';

//分页列表
const URI_DATAGRID = "/security/api/dict/value/datagrid";
//删除
const URI_REMOVE = "/security/api/dict/remove";
//校验
const URI_ADD_VALIDATE = '/security/api/dict/value/validate';
//提交
const URI_ADD_SUBMIT = "/security/api/dict/value/add";
//校验
const URI_UPDATE_VALIDATE = '/security/api/dict/value/validateEdit';
//提交
const URI_UPDATE_SUBMIT = "/security/api/dict/value/edit";

export const datagrid = (params, callback = function(res) {}) => {
	axios.post(URI_DATAGRID, params).then((response) => {
        callback(response.data);
    });
}

export const remove = (ids, callback = function(res) {}) => {
	axios.post(URI_REMOVE, { ids }).then((response) => {
        callback(response.data);
    });
}

export const validateForAdd = (parent_id, value, callback = function(isOk) {}) => {
	axios.post(URI_ADD_VALIDATE, { parent_id, value }).then((response) => {
        callback(response.data == true);
    });
}

export const add = (params, callback = function(res) {}) => {
	axios.post(URI_ADD_SUBMIT, params).then((response) => {
        callback(response.data);
    });
}

export const validateForUpdate = (id, parent_id, value, callback = function(isOk) {}) => {
	axios.post(URI_UPDATE_VALIDATE, { id, parent_id, value }).then((response) => {
        callback(response.data == true);
    });
}

export const update = (params, callback = function(res) {}) => {
	axios.post(URI_UPDATE_SUBMIT, params).then((response) => {
        callback(response.data);
    });
}

export default {
	datagrid,
	remove,
	validateForAdd,
	validateForUpdate,
	add,
	update
}